Skip to content

Fix ProcessJsonRpcClient never clearing the Process output buffers#103

Open
poman wants to merge 1 commit into
playwright-php:mainfrom
poman:fix/processjsonrpcclient-output-buffer-leak
Open

Fix ProcessJsonRpcClient never clearing the Process output buffers#103
poman wants to merge 1 commit into
playwright-php:mainfrom
poman:fix/processjsonrpcclient-output-buffer-leak

Conversation

@poman

@poman poman commented Jul 7, 2026

Copy link
Copy Markdown

Fixes #102

ProcessJsonRpcClient::readProcessOutput() read newly produced bytes from the Node bridge process with Process::getIncrementalOutput() / getIncrementalErrorOutput(), but never called the matching Process::clearOutput() / clearErrorOutput(). Symfony's Process keeps the entire stdout/stderr history in an internal buffer (a php://temp stream that spills to a disk-backed temp file past a small in-memory threshold) for as long as the process object is alive — the incremental getters only track a read cursor, they do not discard what was already consumed.

On a long-lived session (a multi-hour Behat regression run, for example) every JSON-RPC response — page HTML, base64 screenshots, ARIA snapshots — accumulated forever in that buffer. Once the temp file grew large enough to fill the available disk space, Process::addOutput() started silently failing to write further bytes, and every subsequent request in waitForResponse() spun until its deadline and failed with the generic JSON-RPC request N timed out — indistinguishable from a slow browser action or a genuine hang.

Fixes it by calling clearOutput()/clearErrorOutput() right after each incremental read, so the Process buffers stay empty; nothing else reads the accumulated (non-incremental) output.

Testing

  • Added two unit tests on ProcessJsonRpcClient (testReadProcessOutputClearsBothProcessBuffers, testReadProcessOutputClearsBuffersAcrossMultiplePolls) asserting clearOutput()/clearErrorOutput() are called once per poll — verified both fail against the pre-fix code (0 calls observed) and pass with the fix.
  • Full unit suite: 798/798 passing (2 pre-existing, unrelated deprecation warnings elsewhere).
  • php-cs-fixer --dry-run clean; phpstan analyse (level 10) reports 0 errors on the changed files.

Discovered while running the OroCommerce Behat regression suite on this driver: several nodes started failing late in the run with unexplained JSON-RPC request N timed out errors, traced back to full CI-node disks.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ProcessJsonRpcClient never clears the Process output buffers, leaking memory/disk until every request times out

1 participant